<?php
/**
 * report.php 数据服务类
 */

class AdminService extends Service {
    public $table;
    public $adminLimit=20;

	function __construct() {
		parent::__construct();
        $this->table = '20170718coupon_admin';
	}

	// 是否已经是管理员
	function isLogedByOpenid($openid) {
		if(!$openid) return false;
		$sql = "select * from `{$this->table}` where openid='{$openid}'";
		$_list = $this->db->executeSQL($sql);
        //print_r($_list);
        //echo $this->db->lastQuery;
        //exit;
		return is_array($_list)?true:false;
	}

	// 获取信息
	function getByOpenid($openid) {
		if(!$openid) return false;
		$sql = "select * from `{$this->table}` where openid='{$openid}' limit 0,1" ;
		$_list = $this->db->executeSQL($sql);
		return $_list[0];
	}

	// 添加记录
	function addByOpenid($openid) {
		if(!$openid) {return;}
		$addtime = time();
		$sql = "insert into `{$this->table}` (`openid`,`addtime`) values ('{$openid}', {$addtime})";
		$this->db->executeSQL($sql);
		return $this->db->lastInsertID();
	}

	// 获取管理员数量
	function count() {
		$sql = "select count(id) num from `{$this->table}`";
		$rst = $this->db->executeSQL($sql);
		return $rst[0]['num'];
	}
}
?>
